# **********************OBJ INFO**************************
# Author:YuKalix
# @Time    : 2019-11-30 21:28
# @Site    : 52ziyu.cn
# @File    : object_recognition.py
# @software: PyCharm
# *********************************************************

from aip import AipImageClassify



class ObjectRecognition:
    def __init__(self):
        self.APP_ID = '17253919'
        self.API_KEY = 'YRu7fp9sg6OT05RAk3mYjdlo'
        self.SECRET_KEY = 'dPKlIPhWkk9NEG48k3G3QOjq56Z5fGVH'
        self.client = AipImageClassify(self.APP_ID, self.API_KEY, self.SECRET_KEY)

    """ 读取图片 """
    def get_file_content(self, filePath):
        with open(filePath, 'rb') as fp:
            return fp.read()

    def main(self):
        Result = ['当前画面中主要的物体有:']
        image = self.get_file_content(r'obj.jpg')

        """ 如果有可选参数 """
        options = {}
        options["top_num"] = 1
        options["baike_num"] = 1

        result = self.client.animalDetect(image, options)
        # result = self.client.advancedGeneral(image, options)

        IdentifyType = result["result"][0]["name"]
        if IdentifyType == "非动物":
            Result.append("并未在画面中找到小动物")
            print(Result)
        else:
            Result.append("{0}".format(IdentifyType))
            print(Result)
        return Result



if __name__ == '__main__':
    S = ObjectRecognition()
    a = S.main()

    # from TextRecognitionSpeechOutput import TextRecognitionSpeechOutput
    # T = TextRecognitionSpeechOutput()
    # T.main(str(a))
